package operations;

import books.Book;
import books.BookList;

import java.util.Scanner;

public class FindOperation implements IOperation{
    @Override
    public void work(BookList bookList){
        System.out.println("查找图书");
        System.out.println("请输入要查找的图书名");
        Scanner scanner = new Scanner(System.in);
        String name = scanner.nextLine();

        // 遍历数组 查找书籍
        int CurentSize = bookList.getUsedSize();//数组此时的书的数量
        for (int i = 0; i < CurentSize; i++) {
            Book book = bookList.getPos(i);
            if(name.equals(book.getName())){
                System.out.println("找到了这本书!\n"+book);   // 输出提示并打印图书信息
                return;
            }
        }
        System.out.println("这本书不存在");
    }
}
